home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1475 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.4 KB

  1. Path: ix.netcom.com!netnews
  2. From: aschen@ix.netcom.com (Sean Aschen)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Why use private class members instead of protected?
  5. Date: Thu, 11 Jan 1996 07:08:47 GMT
  6. Organization: Netcom
  7. Message-ID: <30f4b64e.624277@nntp.ix.netcom.com>
  8. References: <30F4AB49.6ABB@sierra.net>
  9. NNTP-Posting-Host: ix-dby-ct2-16.ix.netcom.com
  10. X-NETCOM-Date: Wed Jan 10 11:20:24 PM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. On Wed, 10 Jan 1996 22:16:41 -0800, TGColwell <snowbull@sierra.net>
  14. wrote:
  15.  
  16. >I'm relatively new to c++.  I have one quick question:  If child 
  17. >classes can only access protected members of the parent class, 
  18. >why make any members of any class private?  Wouldn't it be 
  19. >better to make members of the parent class protected so that the 
  20. >class is alway "inheritance ready"?
  21. >
  22. >Thanks in advance,
  23. >
  24. >-Tyler
  25. Depends on who will be using your class.  It is better to create a
  26. function/method which manipulates the data member of the parent class.
  27. This way the parent class knows exactly what to expect.  Otherwise, a
  28. derived class may alter data members in a way which you didn't account
  29. for when creating the base class, causing problems.  The whole purpose
  30. for object-oriented data stuctures is data-encapsulation.  Using
  31. protected data members violates that encapsulation.  Actually, most of
  32. my classes don't go any further than my own system, so I use protected
  33. all the time: makes for less typing.
  34.  
  35. Hope that made sense...
  36.  
  37.  
  38.